<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>我的文件</title>
		<!--#include file="/pub-page/sd_load_js.html" -->
		<script type="text/javascript" src="/nresource/js/myFileList.js" ></script>
		<!--#include file="/pub-page/sd_load_css.html" -->
	</head>
	<body>
		<div class="container-fluid">
			<div class="row">
				<div class="col-lg-12 col-md-12 col-sm-12 mgt-10">
					<div class="row mgb-10 mgt-10">
						<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
							<button class="layui-btn layui-btn-sm">
								<i class="layui-icon" onclick="deletePhysical();">&#x1006;</i>彻底删除
							</button>
							<button class="layui-btn layui-btn-sm">
								<i class="layui-icon" onclick="recoveryMulFile();">&#x1002;</i>恢复
							</button>
						</div>
						<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 col-lg-offset-3 col-md-offset-3 col-sm-offset-3">
							<div class="input-group">
								<input type="text" id="fileNameInput" class="form-control">
								<span class="input-group-btn">
									<button class="btn btn-default" type="button" onclick="search(1);">搜索</button>
								</span>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-lg-12" id="fileList">
							
						</div>
					</div>
					<!-- 分页 -->
					<div class="row">
						<div id="pageDiv" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="display: none;"></div>
					</div>					
				</div>
			</div>
		</div>
		<script type="text/javascript">
			var currentPage = 1;
			var pageSize = 9;
			var pageLayer;
			layui.use('layer',function(){
				pageLayer = layui.layer;
			});
			
			
			$(function(){
				search(1);
			});
			
			/**
			 * 查询
			 * @param {Object} pageNo
			 */
			function search(pageNo){
				var fileName = encodeURIComponent(encodeURIComponent($("#fileNameInput").val()));
				var url = "/sd_fm/rest/recyclebin/list?fileName=" + fileName + "&pageNo=" + pageNo + "&pageSize=" + pageSize;
				
				require(['ajaxUtil','template'], function(ajaxUtil, template){
					ajaxUtil.doGet(url, function(data){
						if(data.code == 0){
							var totalCount = data.totalCount;
							//有文件
							if(totalCount > 0){
								if(1 == pageNo){
									$("#pageDiv").css('display','');
									createPage(pageSize, data.totalCount);
								}
								template.importSDM('/fileManage/recyclebinFileList.sdm','#fileList',function(vueObject){
									
								},data);
							}else{//没有文件
								$("#pageDiv").css('display','none');
								$('#fileList').html("<hr/><h4 class='text-danger text-center'>没有文件!</h4>");
							}
						}else{
							
						}
					});
				});
			}		
			/**
			 * 
			 * @param {Object} pageSize
			 * @param {Object} totalCount
			 */
			function createPage(pageSize, totalCount){
				layui.use('laypage',function(){
					var laypage = layui.laypage;
					
					laypage.render({
						elem:'pageDiv',
						count:totalCount,
						limit:pageSize,
						jump:function(obj, first){
							currentPage = obj.curr;
							if(!first){
								search(currentPage);
							}
						}
					});
				});
			}
			/**
			 * 全选
			 */
			function selectAll(obj){
				var fileBoxList = document.getElementsByName("fileBox");
				if(obj.checked){
					for(var i = 0; i < fileBoxList.length; i++){
						fileBoxList[i].checked = true;
					}
				}else{
					for(var i = 0; i < fileBoxList.length; i++){
						fileBoxList[i].checked = false;
					}		
				}
			}
			/**
			 * 恢复文件
			 * @param {Object} fileId
			 */
			function recoveryFile(fileId){
				var url = "/sd_fm/rest/recyclebin/recover";
				var params = {};
				var fileIdArray = [];
		
				fileIdArray.push(fileId);
				params.fileIdArray = fileIdArray;
				
				require(['ajaxUtil'],function(ajaxUtil){
					ajaxUtil.doPost(url, function(data){
						if(data.code == 0){
							pageLayer.alert(data.message);
							search(currentPage);
						}else{
							pageLayer.alert(data.message);
						}
					},params);
				});
			}
			/**
			 * 恢复文件
			 * @param {Object} fileId
			 */
			function recoveryMulFile(){
				var url = "/sd_fm/rest/recyclebin/recover";
				var fileBoxList = document.getElementsByName("fileBox");
				var fileIdArray = [];
				for(var i = 0; i < fileBoxList.length; i++){
					if(fileBoxList[i].checked == true){
						fileIdArray.push(fileBoxList[i].value);
					}
				}
				var params = {};
				params.fileIdArray = fileIdArray;
				
				require(['ajaxUtil'],function(ajaxUtil){
					ajaxUtil.doPost(url, function(data){
						if(data.code == 0){
							pageLayer.alert(data.message);
							search(currentPage);
						}else{
							pageLayer.alert(data.message);
						}
					},params);
				});
			}
			
			/**
			 * 彻底删除
			 */
			function deletePhysical(){
				var url = "/sd_fm/rest/fileInfo/deleteFileById";
				var fileBoxList = document.getElementsByName("fileBox");
				var fileIdArray = [];
				for(var i = 0; i < fileBoxList.length; i++){
					if(fileBoxList[i].checked == true){
						fileIdArray.push(fileBoxList[i].value);
					}
				}
				var params = {};
				params.fileIdArray = fileIdArray;
				params.type = '2';
				
				require(['ajaxUtil'],function(ajaxUtil){
					ajaxUtil.doPost(url, function(data){
						if(data.code == 0){
							pageLayer.alert(data.message);
							search(currentPage);
						}else{
							pageLayer.alert(data.message);
						}
					},params);
				});
			}
			
		</script>
	</body>
</html>
